import 'package:flutter/material.dart';
import 'package:short_video_app/other/user_manager.dart';
import 'package:short_video_app/other/global.dart';
import 'package:short_video_app/utils/navigator_util.dart';
import 'package:short_video_app/ui/pages/common/login_page.dart';

class CustomGesture extends StatelessWidget {
  final Widget? child;
  final HitTestBehavior? behavior;
  final GestureTapCallback? onTap;

  const CustomGesture({
    Key? key,
    this.child,
    this.behavior = HitTestBehavior.opaque,
    this.onTap
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: behavior,
      onTap: () async {
        String? token = await UserManager().getToken();
        if (token == null || token.isEmpty) {
          NavigatorUtil.push(Global.navigatorKey.currentState!.context, const LoginPage());
        } else {
          onTap?.call();
        }
      },
      child: child,
    );
  }
}
